#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require "#{LKP_SRC}/lib/string_ext"

results = Hash.new { |h, k| h[k] = [] }

def stat_line(line, results)
  line = line.resolve_invalid_bytes

  case line
  when /^(.+? ).*\[passed\]/
    results['passes'] += $1.rstrip.tr('/', '.').split
  when /^(.+? ).*\[failed\]/
    results['failures'] += $1.rstrip.tr('/', '.').split
  when /^(.+? ).*\[not run\]/
    results['skips'] += $1.rstrip.tr('/', '.').split
  when /^(.+?\/\*\*\*).*\[not run\]/
    results['skips'] += $1.tr('/', '.').split
  when /^(.+? ).*\[ignored by lkp\]/
    puts "#{$1.rstrip.tr('/', '.')}.ignored_by_lkp: 1"
  end
end

while (line = STDIN.gets)
  stat_line(line, results)
end

results['passes'].each { |seq| puts "#{seq}.pass: 1" }
results['skips'].each { |seq| puts "#{seq}.skip: 1" }
results['failures'].each { |seq| puts "#{seq}.fail: 1" }
